import axios from 'axios';

const prefix = process.env.NODE_ENV === 'development' ? '/api' : '';
const create_chapter = prefix + '/project/projects/save';
const chapter_list = prefix + '/project/projects/list';
const chapter_delete = prefix + '/knowledge/chapter/delete';
const create_chaptervideo = prefix + '/knowledge/chapter/save';

const chaptershow_list = prefix + '/knowledge/chapter/list';

export default {
  createChapterVideo: function (parameters, callback, errorHandler) {
    axios.post(create_chaptervideo, {
      courseId: parameters[0],
      originalFilename: parameters[1],
      materialType: parameters[2],
      materialAddr: parameters[3],
      materialSize: parameters[4],
      description: parameters[5],
      title: parameters[6]
    }).then(function (resp) {
      callback(resp.data);
    }).catch(function (resp) {
      errorHandler(resp);
    });
  },
  createChapter: function (parameters, callback, errorHandler) {
    axios.get(create_chapter, {
      courseId: parameters[0],
      originalFilename: parameters[1],
      materialType: parameters[2],
      materialAddr: parameters[3],
      materialSize: parameters[4],
      description: parameters[5],
      title: parameters[6]
    }).then(function (resp) {
      callback(resp.data);
    }).catch(function (resp) {
      errorHandler(resp);
    });
  },

  fetchChapterList: function (courseId, callback, errorHandler) {
    axios.get(chapter_list, {
      params: {
        courseId: courseId
      }
    }).then(function (resp) {
      callback(resp.data.respObject);
    }).catch(function (resp) {
      errorHandler(resp);
    });
  },

  deleteChapter: function (chapterId, callback, errorHandler) {
    axios.get(chapter_delete, {
      params: {
        chapterId: chapterId
      }
    }).then(function (resp) {
      callback(resp.data);
    }).catch(function (resp) {
      errorHandler(resp);
    });
  },
  fetchChapterShowList: function (courseId, callback, errorHandler) {
    axios.get(chaptershow_list, {
      params: {
        courseId: courseId
      }
    }).then(function (resp) {
      callback(resp.data.chapterDOList);
    }).catch(function (resp) {
      errorHandler(resp);
    });
  },
}
